package com.example.hp.zyfypt411sy.fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.example.hp.zyfypt411sy.R;
import com.example.hp.zyfypt411sy.activity.CmainActivity;

import static android.content.Context.MODE_PRIVATE;

/**
 * Created by Mac on 2017/4/9.
 */

public class Fragment6 extends Fragment {
    private  TextView tvinfo,tvuserid,tvpassword,tvrealname,tvage;
    private Button btnzx,btnfh,btc;
    private SharedPreferences sp;
    private String username;
    private View view=null;
    private Context context;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        context=getActivity();
        //动态加载Fragment1的布局文件
        view=inflater.inflate(R.layout.fragment6,container,false);
        //获取布局上的控件，注意通过view获取
        tvinfo=(TextView)view.findViewById(R.id.textView8);
        btc=(Button)view.findViewById(R.id.button6);
        btc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()){
                    case R.id.button6:
                        Intent intent = new Intent();
                        intent.setClass(getActivity(),CmainActivity.class);//forward为当前activity，forwardTarget为新的activity
                        startActivity(intent);
                        break;
                }
            }
        });
        btnzx=(Button)view.findViewById(R.id.button11);
        btnfh=(Button)view.findViewById(R.id.button7);
        tvrealname=(TextView)view.findViewById(R.id.realname1);
        tvinfo.setText("我的资源");
        btnfh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()){
                    case R.id.button7:
                        getActivity().onBackPressed();
                        break;
                    /*case R.id.button6:
                        Intent intent = new Intent();
                        intent.setClass(MainActivity.this,CmainActivity.class);//forward为当前activity，forwardTarget为新的activity
                        startActivity(intent);
                        break;*/
                }
            }
        });
        sp=context.getSharedPreferences("login",MODE_PRIVATE);
        readSP();
        tvrealname.setText(username);
        //注意Toast第一个参数上下文
        Toast.makeText(context, "加载Fragment我", Toast.LENGTH_SHORT).show();
        //返回动态生成的view
        return view;
    }

    private void readSP() {
        username = sp.getString("username", null);
    }
}